{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import random\n",
    "import faker as FK"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>userName</th>\n",
       "      <th>name</th>\n",
       "      <th>sex</th>\n",
       "      <th>company</th>\n",
       "      <th>address</th>\n",
       "      <th>email</th>\n",
       "      <th>date_of_birth</th>\n",
       "      <th>credit_card_number</th>\n",
       "      <th>credit_card_full</th>\n",
       "      <th>city_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>yangqiao</td>\n",
       "      <td>林桂珍</td>\n",
       "      <td>男</td>\n",
       "      <td>鑫博腾飞网络有限公司</td>\n",
       "      <td>浙江省太原县永川陈街a座 728684</td>\n",
       "      <td>linjun@yahoo.com</td>\n",
       "      <td>2013-11-07</td>\n",
       "      <td>6584052372874638</td>\n",
       "      <td>VISA 16 digit\\n志强 李\\n4609051276977857 06/26\\nC...</td>\n",
       "      <td>沈阳</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>zengqiang</td>\n",
       "      <td>钱旭</td>\n",
       "      <td>男</td>\n",
       "      <td>富罳信息有限公司</td>\n",
       "      <td>河南省博县大兴李路i座 714038</td>\n",
       "      <td>jtang@50.net</td>\n",
       "      <td>1962-04-02</td>\n",
       "      <td>501833442012</td>\n",
       "      <td>Diners Club / Carte Blanche\\n雪梅 秦\\n30096345266...</td>\n",
       "      <td>梧州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>oyin</td>\n",
       "      <td>郭秀云</td>\n",
       "      <td>男</td>\n",
       "      <td>天开科技有限公司</td>\n",
       "      <td>甘肃省鹏市普陀福州路c座 905342</td>\n",
       "      <td>yuangang@yahoo.com</td>\n",
       "      <td>1953-07-07</td>\n",
       "      <td>2233873167253959</td>\n",
       "      <td>Maestro\\n桂兰 植\\n502076735286 02/29\\nCVV: 904\\n</td>\n",
       "      <td>石家庄</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>qianghan</td>\n",
       "      <td>曹淑珍</td>\n",
       "      <td>男</td>\n",
       "      <td>凌颖信息信息有限公司</td>\n",
       "      <td>内蒙古自治区金凤县南湖马路I座 735174</td>\n",
       "      <td>qiang80@yahoo.com</td>\n",
       "      <td>1979-11-17</td>\n",
       "      <td>586976961779</td>\n",
       "      <td>JCB 16 digit\\n丽 杨\\n3514231985712268 10/23\\nCVC...</td>\n",
       "      <td>巢湖</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>pingyao</td>\n",
       "      <td>李丹</td>\n",
       "      <td>女</td>\n",
       "      <td>超艺信息有限公司</td>\n",
       "      <td>浙江省云县璧山澳门路h座 548805</td>\n",
       "      <td>yongcheng@minhan.cn</td>\n",
       "      <td>1919-07-30</td>\n",
       "      <td>2269383428654992</td>\n",
       "      <td>JCB 16 digit\\n秀梅 王\\n3567838509930055 10/23\\nCV...</td>\n",
       "      <td>佛山</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>tao62</td>\n",
       "      <td>鲁婷</td>\n",
       "      <td>女</td>\n",
       "      <td>双敏电子网络有限公司</td>\n",
       "      <td>江苏省波县牧野通辽街q座 177868</td>\n",
       "      <td>qiang32@hotmail.com</td>\n",
       "      <td>1970-05-14</td>\n",
       "      <td>4603582666323068</td>\n",
       "      <td>JCB 16 digit\\n志强 王\\n3565421327532916 02/28\\nCV...</td>\n",
       "      <td>兴城</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>longtao</td>\n",
       "      <td>陈欢</td>\n",
       "      <td>男</td>\n",
       "      <td>鑫博腾飞科技有限公司</td>\n",
       "      <td>上海市海门市高港刘路n座 198872</td>\n",
       "      <td>zhugang@yahoo.com</td>\n",
       "      <td>2013-02-11</td>\n",
       "      <td>4625824688470196078</td>\n",
       "      <td>VISA 16 digit\\n瑞 郑\\n4658314153520699 04/24\\nCV...</td>\n",
       "      <td>淮安</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>yongdeng</td>\n",
       "      <td>刘玉兰</td>\n",
       "      <td>男</td>\n",
       "      <td>华成育卓信息有限公司</td>\n",
       "      <td>贵州省红县高坪王街R座 755462</td>\n",
       "      <td>na43@31.cn</td>\n",
       "      <td>1965-07-01</td>\n",
       "      <td>5541963801617675</td>\n",
       "      <td>JCB 16 digit\\n萍 邹\\n3568065603791790 12/24\\nCVC...</td>\n",
       "      <td>潮州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>xia82</td>\n",
       "      <td>卢磊</td>\n",
       "      <td>女</td>\n",
       "      <td>中建创业网络有限公司</td>\n",
       "      <td>吉林省汕尾市山亭邓路M座 930380</td>\n",
       "      <td>gangxiong@gmail.com</td>\n",
       "      <td>1916-11-16</td>\n",
       "      <td>4090427150763132</td>\n",
       "      <td>Diners Club / Carte Blanche\\n丹丹 郭\\n30439426547...</td>\n",
       "      <td>太原</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>xiulanyan</td>\n",
       "      <td>刘秀珍</td>\n",
       "      <td>男</td>\n",
       "      <td>万迅电脑网络有限公司</td>\n",
       "      <td>河南省建县江北杨路k座 794419</td>\n",
       "      <td>liaotao@hotmail.com</td>\n",
       "      <td>1909-10-11</td>\n",
       "      <td>6505669479347311</td>\n",
       "      <td>VISA 16 digit\\n敏 杨\\n4327269106976367 06/31\\nCV...</td>\n",
       "      <td>兴安盟</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      userName name sex     company                 address  \\\n",
       "0     yangqiao  林桂珍   男  鑫博腾飞网络有限公司     浙江省太原县永川陈街a座 728684   \n",
       "1    zengqiang   钱旭   男    富罳信息有限公司      河南省博县大兴李路i座 714038   \n",
       "2         oyin  郭秀云   男    天开科技有限公司     甘肃省鹏市普陀福州路c座 905342   \n",
       "3     qianghan  曹淑珍   男  凌颖信息信息有限公司  内蒙古自治区金凤县南湖马路I座 735174   \n",
       "4      pingyao   李丹   女    超艺信息有限公司     浙江省云县璧山澳门路h座 548805   \n",
       "..         ...  ...  ..         ...                     ...   \n",
       "995      tao62   鲁婷   女  双敏电子网络有限公司     江苏省波县牧野通辽街q座 177868   \n",
       "996    longtao   陈欢   男  鑫博腾飞科技有限公司     上海市海门市高港刘路n座 198872   \n",
       "997   yongdeng  刘玉兰   男  华成育卓信息有限公司      贵州省红县高坪王街R座 755462   \n",
       "998      xia82   卢磊   女  中建创业网络有限公司     吉林省汕尾市山亭邓路M座 930380   \n",
       "999  xiulanyan  刘秀珍   男  万迅电脑网络有限公司      河南省建县江北杨路k座 794419   \n",
       "\n",
       "                   email date_of_birth   credit_card_number  \\\n",
       "0       linjun@yahoo.com    2013-11-07     6584052372874638   \n",
       "1           jtang@50.net    1962-04-02         501833442012   \n",
       "2     yuangang@yahoo.com    1953-07-07     2233873167253959   \n",
       "3      qiang80@yahoo.com    1979-11-17         586976961779   \n",
       "4    yongcheng@minhan.cn    1919-07-30     2269383428654992   \n",
       "..                   ...           ...                  ...   \n",
       "995  qiang32@hotmail.com    1970-05-14     4603582666323068   \n",
       "996    zhugang@yahoo.com    2013-02-11  4625824688470196078   \n",
       "997           na43@31.cn    1965-07-01     5541963801617675   \n",
       "998  gangxiong@gmail.com    1916-11-16     4090427150763132   \n",
       "999  liaotao@hotmail.com    1909-10-11     6505669479347311   \n",
       "\n",
       "                                      credit_card_full city_name  \n",
       "0    VISA 16 digit\\n志强 李\\n4609051276977857 06/26\\nC...        沈阳  \n",
       "1    Diners Club / Carte Blanche\\n雪梅 秦\\n30096345266...        梧州  \n",
       "2        Maestro\\n桂兰 植\\n502076735286 02/29\\nCVV: 904\\n       石家庄  \n",
       "3    JCB 16 digit\\n丽 杨\\n3514231985712268 10/23\\nCVC...        巢湖  \n",
       "4    JCB 16 digit\\n秀梅 王\\n3567838509930055 10/23\\nCV...        佛山  \n",
       "..                                                 ...       ...  \n",
       "995  JCB 16 digit\\n志强 王\\n3565421327532916 02/28\\nCV...        兴城  \n",
       "996  VISA 16 digit\\n瑞 郑\\n4658314153520699 04/24\\nCV...        淮安  \n",
       "997  JCB 16 digit\\n萍 邹\\n3568065603791790 12/24\\nCVC...        潮州  \n",
       "998  Diners Club / Carte Blanche\\n丹丹 郭\\n30439426547...        太原  \n",
       "999  VISA 16 digit\\n敏 杨\\n4327269106976367 06/31\\nCV...       兴安盟  \n",
       "\n",
       "[1000 rows x 10 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "fk = FK.Faker(locale='zh_cn')\n",
    "#fk.user_name()\n",
    "#fk.name()\n",
    "#fk.address()\n",
    "cnt = 1000\n",
    "\n",
    "\n",
    "df = pd.DataFrame({'userName': [fk.user_name() for i in range(0, cnt)], \n",
    "             'name': [fk.name() for i in range(0, cnt)], \n",
    "             'sex': random.choices('男女', k=cnt),\n",
    "             'company': [fk.company() for i in range(0, cnt)], \n",
    "             'address': [fk.address() for i in range(0, cnt)], \n",
    "             'email': [fk.ascii_email() for i in range(0, cnt)], \n",
    "             'date_of_birth': [fk.date_of_birth() for i in range(0, cnt)], \n",
    "             'credit_card_number': [fk.credit_card_number() for i in range(0, cnt)], \n",
    "             'credit_card_full': [fk.credit_card_full() for i in range(0, cnt)], \n",
    "             'city_name': [fk.city_name() for i in range(0, cnt)], \n",
    "\n",
    "})\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAIAAADTED8xAAAIuElEQVR4nO3dzXXbSBOF4dYcb5SEnJsOI1AgioB7pSU5CW+9wAwGBkUQ/V91632238w3PGDdvtWWST19vn4kIKp/Zr8AYCYCgFo/f/2e/RLKEQBUcT39iQCgxs9fv9+v19mvogoBQGgEAIUEjv9EAFBGY/oTAUABmelPBAC5lKY/jQyA9z8vg6RBAWD6NYgd/2lkA7xfr8TANb3pT2MCIPngolF9E4degikBWNM9AKonRyjHb6Lrc40/BsUD2kdY3wDcPjvXp0VA2tOfaAAckJ/+1DUA9x4fJQA7aAB8L8Lxn/oFIMjjUxXn7ZvTAGxBlsWZ/tQpAKGeoJho7920OwAlAAvaByDaEaIk4HvHnwLhXwGnPzUPQNZDZAuyI+b0JxoAKfD0p7YBKHiOlADmogGii3z8p4YBKH6OlMBEwac/0QCRMf2pVQB4lHDKRAOwBY3HmbVoEAAepTu8ZSsTDZAogYGY/q3aAPA0feH92rHSAMAUVQFoe5ywBfXG8X+LBoii6/T7PbzKA9Djgfp9jsZx9t9DA+hj+g8UBoBnCg3mGoAtq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ASB7/HPBB1AZAY/oZ97CqAuB3+tlnsCgPgKPp54DHPYKXYMYd5xUGwNTxzz6DYiUBmDv9HPBoKDsAg6efcUdXtu4AjDsGywtA8+Of9R1zZQSgfvo54GHN2QAUTD/jDvtOBeDk9LPPwJ3ySzAHPAQ8DsBy/DPukPT0+fpx8D+vn2dl3CHpQQMw99DG16IgNAKA0AgAQiMACI0AIDQCgNAIAEIjAAiNACA0AoDQCABCIwAIjQAgNAKA0AgAQiMACI0AIDQCgNAIAEIjAAjtD2gI4Pqy5XWsAAAAAElFTkSuQmCC",
      "text/plain": [
       "<PIL.PngImagePlugin.PngImageFile image mode=RGB size=256x256 at 0x7FDC61C8BAC8>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from PIL import Image\n",
    "from io import BytesIO\n",
    "\n",
    "Image.open(BytesIO(fk.image()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "userName              object\n",
       "name                  object\n",
       "sex                   object\n",
       "company               object\n",
       "address               object\n",
       "email                 object\n",
       "date_of_birth         object\n",
       "credit_card_number    object\n",
       "credit_card_full      object\n",
       "city_name             object\n",
       "dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.convert_dtypes()\n",
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>累计</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>姓名</th>\n",
       "      <th>公司</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>丁丽华</th>\n",
       "      <th>飞海科技网络有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁兵</th>\n",
       "      <th>万迅电脑信息有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁琴</th>\n",
       "      <th>维涛信息有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁秀珍</th>\n",
       "      <th>万迅电脑传媒有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>万利</th>\n",
       "      <th>联软网络有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黎静</th>\n",
       "      <th>信诚致远信息有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙婷</th>\n",
       "      <th>创汇信息有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙建华</th>\n",
       "      <th>菊风公司传媒有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙杨</th>\n",
       "      <th>天益传媒有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龚强</th>\n",
       "      <th>巨奥网络有限公司</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>999 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                累计\n",
       "姓名  公司            \n",
       "丁丽华 飞海科技网络有限公司   1\n",
       "丁兵  万迅电脑信息有限公司   1\n",
       "丁琴  维涛信息有限公司     1\n",
       "丁秀珍 万迅电脑传媒有限公司   1\n",
       "万利  联软网络有限公司     1\n",
       "...             ..\n",
       "黎静  信诚致远信息有限公司   1\n",
       "龙婷  创汇信息有限公司     1\n",
       "龙建华 菊风公司传媒有限公司   1\n",
       "龙杨  天益传媒有限公司     1\n",
       "龚强  巨奥网络有限公司     1\n",
       "\n",
       "[999 rows x 1 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(df.groupby(['name', 'company']).size()\n",
    "    .reset_index()\n",
    "    .rename({\"name\": '姓名', 'company': '公司', 0:\"累计\"}, axis=1)\n",
    "    .set_index(['姓名','公司'])\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "userName              object\n",
       "name                  object\n",
       "sex                   object\n",
       "company               object\n",
       "address               object\n",
       "email                 object\n",
       "date_of_birth         object\n",
       "credit_card_number    object\n",
       "credit_card_full      object\n",
       "city_name             object\n",
       "dtype: object"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "userName                      object\n",
       "name                          object\n",
       "sex                           object\n",
       "company                       object\n",
       "address                       object\n",
       "email                         object\n",
       "date_of_birth         datetime64[ns]\n",
       "credit_card_number            object\n",
       "credit_card_full              object\n",
       "city_name                     object\n",
       "dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import datetime\n",
    "#df.astype({\"date_of_birth\": datetime.time})\n",
    "df['date_of_birth'] = pd.to_datetime(df['date_of_birth'])\n",
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(女, 01)    39\n",
       "(女, 02)    24\n",
       "(女, 03)    48\n",
       "(女, 04)    39\n",
       "(女, 05)    46\n",
       "(女, 06)    38\n",
       "(女, 07)    52\n",
       "(女, 08)    38\n",
       "(女, 09)    38\n",
       "(女, 10)    35\n",
       "(女, 11)    37\n",
       "(女, 12)    44\n",
       "(男, 01)    45\n",
       "(男, 02)    36\n",
       "(男, 03)    46\n",
       "(男, 04)    49\n",
       "(男, 05)    49\n",
       "(男, 06)    37\n",
       "(男, 07)    54\n",
       "(男, 08)    43\n",
       "(男, 09)    29\n",
       "(男, 10)    45\n",
       "(男, 11)    50\n",
       "(男, 12)    39\n",
       "dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "df.groupby(by=lambda i: (df.loc[i].sex, df.loc[i].date_of_birth.strftime('%m'))).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex  date_of_birth\n",
       "女    01               39\n",
       "     02               24\n",
       "     03               48\n",
       "     04               39\n",
       "     05               46\n",
       "     06               38\n",
       "     07               52\n",
       "     08               38\n",
       "     09               38\n",
       "     10               35\n",
       "     11               37\n",
       "     12               44\n",
       "男    01               45\n",
       "     02               36\n",
       "     03               46\n",
       "     04               49\n",
       "     05               49\n",
       "     06               37\n",
       "     07               54\n",
       "     08               43\n",
       "     09               29\n",
       "     10               45\n",
       "     11               50\n",
       "     12               39\n",
       "dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby( [df.sex, df['date_of_birth'].apply(lambda x: x.strftime('%m') )]).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sex  月 \n",
       "女    01    39\n",
       "     02    24\n",
       "     03    48\n",
       "     04    39\n",
       "     05    46\n",
       "     06    38\n",
       "     07    52\n",
       "     08    38\n",
       "     09    38\n",
       "     10    35\n",
       "     11    37\n",
       "     12    44\n",
       "男    01    45\n",
       "     02    36\n",
       "     03    46\n",
       "     04    49\n",
       "     05    49\n",
       "     06    37\n",
       "     07    54\n",
       "     08    43\n",
       "     09    29\n",
       "     10    45\n",
       "     11    50\n",
       "     12    39\n",
       "dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['月'] = df['date_of_birth'].apply(lambda x: x.strftime('%m'))\n",
    "df.groupby(['sex', '月']).size()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'07'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[2].date_of_birth.strftime('%d')\n",
    "#time.mktime(df.loc[2].date_of_birth.timetuple())\n",
    "#time.strftime('%d', time.mktime(df.loc[2].date_of_birth))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>姓名</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>丁丽华</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁兵</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁琴</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>丁秀珍</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>万利</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>黎静</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙婷</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙建华</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龙杨</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>龚强</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>897 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      姓名\n",
       "name    \n",
       "丁丽华    1\n",
       "丁兵     1\n",
       "丁琴     1\n",
       "丁秀珍    1\n",
       "万利     1\n",
       "...   ..\n",
       "黎静     1\n",
       "龙婷     1\n",
       "龙建华    1\n",
       "龙杨     1\n",
       "龚强     1\n",
       "\n",
       "[897 rows x 1 columns]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DataFrame({'姓名': df.groupby(['name']).size()})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df.to_csv(\"./test.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "103"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "#df['userName'].apply(lambda x: x[1:])"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
  },
  "kernelspec": {
   "display_name": "Python 3.7.3 64-bit",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
